import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-tab4',
  templateUrl: './tab4.page.html',
  styleUrls: ['./tab4.page.scss'],
})
export class Tab4Page implements OnInit {
  uname = '';
  upwd = '';
  doLogin() {
    console.log(this.uname, this.upwd);
    //post请求发送：特点是路径与参数分开写
    const url = '/api/data/user/login.php';
    const params = `uname=${this.uname}&upwd=${this.upwd}`;
    //需要告知服务器，我们的参数是字符串类型，服务器才能够接受
    const options = {
      headers: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      //ionic默认不开启cookie访问权限，导致服务器的cookie机制不生效
      withCredentials: true, //开启信任模式，允许服务器操作本地的cookie
    };
    this.http.post(url, params, options).subscribe((res) => {
      console.log(res);
    });
  }
  buttons = [
    { icon: 'logo-alipay', color: 'primary' },
    { icon: 'logo-apple', color: 'danger' },
    { icon: 'logo-android', color: 'warning' },
    { icon: 'logo-wechat', color: 'primary' },
    { icon: 'logo-octocat', color: 'secondary' },
    { icon: 'logo-mastodon', color: 'light' },
  ];

  constructor(public http: HttpClient) {}

  ngOnInit() {}
}
